package com.atomscat.lottery.config.redis;

import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.ReactiveRedisTemplate;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

import java.time.Duration;


@Component
@RequiredArgsConstructor
public class OsRedisService {
    private final ReactiveRedisTemplate<String, String> reactiveRedisTemplate;

    public Mono<Boolean> save(String key, String value) {
        return reactiveRedisTemplate.opsForValue().set(key, value);
    }

    public Mono<String> get(String key) {
        return reactiveRedisTemplate.opsForValue().get(key);
    }

    public void delete(String key) {
        reactiveRedisTemplate.delete(key).subscribe();
    }

    public void setExpire(String key, String value, long timeout) {
        reactiveRedisTemplate.opsForValue().set(key, value, timeout).subscribe();
    }

    public void setExpire(String key, String value) {
        reactiveRedisTemplate.opsForValue().set(key, value).subscribe();
    }

    public void setExpire(String key, Duration timeout) {
        reactiveRedisTemplate.expire(key, timeout).subscribe();
    }
}
